﻿/**
 * Project config file includes dev/prod and frontend/backend
 */
var path = require('path')
var _ = require('lodash')

var backendBase = {
  WS_PORT: 9000, // websocket服务端监听端口
  ALARM_PORT: 5140, // udp报警监听端口
  BC_SERVER: '192.168.20.89', // bc服务地址
  BC_PORT: 8000, // bc服务端口
  // Root path of server
  root: path.normalize(__dirname)
}

var development = {
  frontend: {
    port: 9001,
    assetsRoot: path.resolve(__dirname, './src'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      // '/api/local': {
      //   target: 'http://192.168.20.135:8360',
      //   changeOrigin: true
      // },
      '/api': {
        target: 'http://192.168.7.159:8360',
        changeOrigin: true
      },
      '/api/socket.io': {
        target: 'http://192.168.7.159:8360',
        changeOrigin: true,
        ws: true
      }
    },
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  },
  backend: _.merge({}, backendBase, {
    mongo: {
      // uri: 'mongodb://192.168.20.5/irectoryperdb'
      // uri: 'mongodb://192.168.20.5/vf-backend-dev'
      uri: 'mongodb://192.168.20.5/bs-security'
    }
  })
}
var production = {
  frontend: {
    port: 9001,
    index: path.resolve(__dirname, './dist/index.html'),
    assetsRoot: path.resolve(__dirname, './dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    cssSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    proxyTable: {
      '/api': {
        target: 'http://localhost:' + backendBase.WS_PORT,
        changeOrigin: true
      }
    }
  },
  backend: _.merge({}, backendBase, {
    // whether backend servers the frontend, you can use nginx to server frontend and proxy to backend services
    // if set to true, you need no web services like nginx
    serverFrontend: true,
    // Server IP
    ip: process.env.NODEAPP_HOST || '0.0.0.0',
    // Server port
    port: process.env.NODEAPP_PORT || 9000,
    // MongoDB connection options
    mongo: {
      uri: process.env.MONGODB_URI || process.env.MONGOHQ_URI ||
      'mongodb://192.168.20.5/bs-security'
    },

    // frontend folder
    frontend: path.resolve(__dirname, './dist')
  })
}

var config = process.env.NODE_ENV === 'production' ? production : development

module.exports = _.assign({}, config)
